package com.hnust.fiveonesix.Controller.LogiorRegiController;

import com.hnust.fiveonesix.Mapper.LogiorRegiMapper.LoginMapper;
import com.hnust.fiveonesix.POJO.LoginInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class LoginController {
    @Autowired
    private LoginMapper loginMapper;

    @RequestMapping("/login")
    public String Login(@RequestParam("账号") String UserName,
                        @RequestParam("密码") String pwd,
                        @RequestParam("同意") Integer agree) {
        String userName ='%' + UserName+'%';
        LoginInfo userinfo = loginMapper.getUserinfo(userName);
      
        if(agree==null)
            return "forward:/登录注册失败/请先同意相关协议才能登录.html";
        if(!userinfo.getUserName().trim().equals(UserName))
            return "forward:/登录注册失败/没有这个用户.html";
        if(!userinfo.getUserPwd().trim().equals(pwd))
            return "forward:/登录注册失败/密码错误.html";

        return "商城模板部分/商城首页";//注意不能有html后缀，配置了themeleaf模板引擎后return会返回templates/下的页面
    }
}
